﻿using System;
using System.Collections.Generic;
using System.Configuration;
using WorkstationSystem.Entity;

namespace IntoStationSystem.Global
{
    public class Fields
    {
        /// <summary>
        /// 用户控件名称
        /// </summary>
        public static readonly Dictionary<string, string> ViewNames = new Dictionary<string, string>()
        {
            {"ManualView","设备调试" },
            {"IOStateView","IO测试" },
            {"LogView","日志信息" },
            {"ProductSettingView","型号配置" },
            {"RFIDView","RFID调试" },
            {"DCFanView","风机调试" },
            {"TightenGunView","拧紧枪调试" },
            {"LeakageView","泄露仪调试" },
            {"IV3CameraView","相机调试" },
            {"ShieldDeviceView","屏蔽设置" },
            {"Help","帮助" },
            {"ResetPartCodeView","解绑扫码" },
            {"LoginView","登录" },
            {"ScanQRCodeView","扫码设置" },
            {"SettingView","设置" },
        };
        /// <summary>
        /// PLC 地址映射           
        /// </summary>
        /// Pair<偏移量,长度>
        public static readonly Dictionary<string, Pair<int, int>> Map = new Dictionary<string, Pair<int, int>>()
        {
            {"PageId",                new Pair<int, int>(0,2)},     //画面编号
            {"PageIdFeedBack",        new Pair<int, int>(2,2)},     //画面编号反馈，输出给PC
            {"LocalModelId",          new Pair<int, int>(4,2)},     //生产型号编号
            {"SelectModelId",         new Pair<int, int>(6,2)},     //当前型号编号，输出给PC
            {"TotalProduction",       new Pair<int, int>(8,4)},     //总数量 ，输出给PC
            {"OkQuantity",            new Pair<int, int>(12,4)},    //OK数量 ，输出给PC
            {"NgQuantity",            new Pair<int, int>(16,4)},    //NG数量，输出给PC
            {"CycleTime",             new Pair<int, int>(20,4)},    //节拍时间(S).输出给PC
            {"RunTime",               new Pair<int, int>(24,4)},    //订单运行时间
            {"CraftId",               new Pair<int, int>(28,12)},   //工艺ID（生产身份证）输出给PC12,34
            {"PartId",                new Pair<int, int>(62,34)},   //部件ID（零部件扫码ID）暂时预留
            {"AmendId",               new Pair<int, int>(96,34)},   //人工输入修改ID   暂时预留
#region Sysbit
            //System_ok       BOOL    130.0   系统准备OK
            //Man_mode        BOOL    130.1   调试模式
            //Auto_mode       BOOL    130.2   循环模式
            //Sub_mode        BOOL    130.3   暂停模式
            //Stop_mode       BOOL    130.4   停止模式
            //Rest_mode       BOOL    130.5   复位模式
            //Home_mode       BOOL    130.6   回原位模式
            //E-stop_mode     BOOL    130.7   急停模式
            //System_safe     BOOL    131.0   系统安全
            //Home_position   BOOL    131.1   初始位置
            //Cycle_end       BOOL    131.2   循环任务完成
            //Out_3           BOOL    131.3   预留
            //Out_4           BOOL    131.4   预留
            //Hint            BOOL    131.5   有提示信息发生
            //Warm            BOOL    131.6   有警告信息发送
            //Alarm           BOOL    131.7   有故障信息发送 
	        #endregion
            {"SysBit",                new Pair<int, int>(130,2)},
#region SetButton
            //button[0]   BOOL    132.0   本地/远程
            //button[1]   BOOL    132.1   调试/运行
            //button[2]   BOOL    132.2   预留
            //button[3]   BOOL    132.3   预留
            //button[4]   BOOL    132.4   预留
            //button[5]   BOOL    132.5   预留
            //button[6]   BOOL    132.6   预留
            //button[7]   BOOL    132.7   预留
            //button[8]   BOOL    133.0   预留
            //button[9]   BOOL    133.1   预留
            //button[10]  BOOL    133.2   预留
            //button[11]  BOOL    133.3   预留
            //button[12]  BOOL    133.4   预留
            //button[13]  BOOL    133.5   预留
            //button[14]  BOOL    133.6   预留
            //button[15]  BOOL    133.7   预留
	        #endregion
            {"SetButton",             new Pair<int, int>(132,2)},
#region PulseButton
            //button[0]   BOOL    134.0   循环启动
            //button[1]   BOOL    134.1   循环停止
            //button[2]   BOOL    134.2   故障复位
            //button[3]   BOOL    134.3   回原位
            //button[4]   BOOL    134.4   灯测试
            //button[5]   BOOL    134.5   消音
            //button[6]   BOOL    134.6   预留
            //button[7]   BOOL    134.7   复测
            //button[8]   BOOL    135.0   预留
            //button[9]   BOOL    135.1   预留
            //button[10]  BOOL    135.2   预留
            //button[11]  BOOL    135.3   预留
            //button[12]  BOOL    135.4   预留
            //button[13]  BOOL    135.5   预留
            //button[14]  BOOL    135.6   预留
            //button[15]  BOOL    135.7   预留
#endregion
            {"PulseButton",           new Pair<int, int>(134,2)},
#region Manual
             
            //manual[1]   BOOL    136.0   HMI手动前进1
            //manual[2]   BOOL    136.1   HMI前进中1
            //manual[3]   BOOL    136.2   HMI前进到位1
            //manual[4]   BOOL    136.3   HMI前进安全状态1
            //manual[5]   BOOL    136.4   HMI手动后退1
            //manual[6]   BOOL    136.5   HMI后退中1
            //manual[7]   BOOL    136.6   HMI后退到位1
            //manual[8]   BOOL    136.7   HMI后退安全状态1
            //manual[9]   BOOL    137.0   HMI手动前进2
            //manual[10]  BOOL    137.1   HMI前进中2
            //manual[11]  BOOL    137.2   HMI前进到位2
            //manual[12]  BOOL    137.3   HMI前进安全状态2
            //manual[13]  BOOL    137.4   HMI手动后退2
            //manual[14]  BOOL    137.5   HMI后退中2
            //manual[15]  BOOL    137.6   HMI后退到位2
            //manual[16]  BOOL    137.7   HMI后退安全状态2
            //manual[17]  BOOL    138.0   HMI手动前进3
            //manual[18]  BOOL    138.1   HMI前进中3
            //manual[19]  BOOL    138.2   HMI前进到位3
            //manual[20]  BOOL    138.3   HMI前进安全状态3
            //manual[21]  BOOL    138.4   HMI手动后退3
            //manual[22]  BOOL    138.5   HMI后退中3
            //manual[23]  BOOL    138.6   HMI后退到位3
            //manual[24]  BOOL    138.7   HMI后退安全状态3
            //manual[25]  BOOL    139.0   HMI手动前进4
            //manual[26]  BOOL    139.1   HMI前进中4
            //manual[27]  BOOL    139.2   HMI前进到位4
            //manual[28]  BOOL    139.3   HMI前进安全状态4
            //manual[29]  BOOL    139.4   HMI手动后退4
            //manual[30]  BOOL    139.5   HMI后退中4
            //manual[31]  BOOL    139.6   HMI后退到位4
            //manual[32]  BOOL    139.7   HMI后退安全状态4
            //manual[33]  BOOL    140.0   HMI手动前进5
            //manual[34]  BOOL    140.1   HMI前进中5
            //manual[35]  BOOL    140.2   HMI前进到位5
            //manual[36]  BOOL    140.3   HMI前进安全状态5
            //manual[37]  BOOL    140.4   HMI手动后退5
            //manual[38]  BOOL    140.5   HMI后退中5
            //manual[39]  BOOL    140.6   HMI后退到位5
            //manual[40]  BOOL    140.7   HMI后退安全状态5
	#endregion
            {"Manual",                new Pair<int, int>(136,5)},
            {"Security",              new Pair<int, int>(142,1)},   //安全
            {"Equipment",             new Pair<int, int>(143,1)},   //设备  编码说明：0、故障解除 1、设备发生故障；暂时预留
            {"Material",              new Pair<int, int>(144,1)},   //编码说明：0、物料OK 1、物料缺失 。暂时预留
            {"Quality",               new Pair<int, int>(145,1)},   //编码说明：0、品质正常 1、品质异常。暂时预留
            {"Personnel",             new Pair<int, int>(146,1)},   //编码说明：1、呼叫机修；2、呼叫电修；3、呼叫机电维修。暂时预留
            {"HeartBeat",             new Pair<int, int>(147,1)},   //心跳
            {"RstCode",               new Pair<int, int>(148,1)},   //解绑信号
            {"Step",                  new Pair<int, int>(150,2)},   //配置设备运行状态，步骤提示2. 预留
            {"SetParam",              new Pair<int, int>(168,64)},  //配置参数设置 
            {"ShowParam",             new Pair<int, int>(232,64)},  //配置参数显示
            {"SetId",                 new Pair<int, int>(296,2)},   //暂时停用
            {"InPut",                 new Pair<int, int>(298,2)},   //暂时停用
            {"OutPut",                new Pair<int, int>(300,2)},   //暂时停用
            {"Prompt",                new Pair<int, int>(302,4)},   //配置提示信息
            {"Waring",                new Pair<int, int>(306,4)},   //配置提示信息
            {"Alarm",                 new Pair<int, int>(310,16)},  //配置提示信息
            {"RfidWrite",             new Pair<int, int>(326,16)},
            {"RfidRead",              new Pair<int, int>(328,1)},
            {"RfidPartByte1",         new Pair<int, int>(330,1)},
            {"RfidPartByte2",         new Pair<int, int>(331,1)},
            {"RfidPartByte3",         new Pair<int, int>(332,1)},
            {"RfidPartByte4",         new Pair<int, int>(333,1)},
            {"LableByte",             new Pair<int, int>(334,32)},
            {"RfidGroup1",            new Pair<int, int>(366,40)},
            {"RfidGroup2",            new Pair<int, int>(406,40)},
            {"Group1Write",           new Pair<int, int>(446,1)},
            {"Group1Read",            new Pair<int, int>(448,1)},
            {"Group1Byte",            new Pair<int, int>(450,4)},
            {"Group1SetReal",         new Pair<int, int>(454,32)},
            {"Group1ShowReal",        new Pair<int, int>(486,32)},
            {"Group2Write",           new Pair<int, int>(518,1)},
            {"Group2Read",            new Pair<int, int>(520,1)},
            {"Group2Byte",            new Pair<int, int>(522,4)},
            {"Group2SetReal",         new Pair<int, int>(526,32)},
            {"Group2ShowReal",        new Pair<int, int>(558,32)},
            {"Group3Write",           new Pair<int, int>(590,1)},
            {"Group3Read",            new Pair<int, int>(592,1)},
            {"Group3Byte",            new Pair<int, int>(594,4)},
            {"Group3SetReal",         new Pair<int, int>(598,32)},
            {"Group3ShowReal",        new Pair<int, int>(630,32)},
            {"Group4Write",           new Pair<int, int>(662,1)},
            {"Group4Read",            new Pair<int, int>(664,1)},
            {"Group4Byte",            new Pair<int, int>(666,4)},
            {"Group4SetReal",         new Pair<int, int>(670,32)},
            {"Group4ShowReal",        new Pair<int, int>(702,32)},
            {"Group5Write",           new Pair<int, int>(734,1)},
            {"Group5Read",            new Pair<int, int>(736,1)},
            {"Group5Byte",            new Pair<int, int>(738,4)},
            {"Group5SetReal",         new Pair<int, int>(742,32)},
            {"Group5ShowReal",        new Pair<int, int>(774,32)},
            {"Group6Write",           new Pair<int, int>(806,1)},
            {"Group6Read",            new Pair<int, int>(808,1)},
            {"Group6Byte",            new Pair<int, int>(810,4)},
            {"Group6SetReal",         new Pair<int, int>(814,32)},
            {"Group6ShowReal",        new Pair<int, int>(846,32)},
            {"Group7Write",           new Pair<int, int>(878,1)},
            {"Group7Read",            new Pair<int, int>(880,1)},
            {"Group7Byte",            new Pair<int, int>(882,4)},
            {"Group7SetReal",         new Pair<int, int>(886,32)},
            {"Group7ShowReal",        new Pair<int, int>(918,32)},
            {"SetNumber",             new Pair<int, int>(950,2)},
            {"Number",                new Pair<int, int>(952,2)},
            {"Ratio",                 new Pair<int, int>(954,2)},
            {"Inching",               new Pair<int, int>(956,4)},
            {"CurrentPOPU",           new Pair<int, int>(960,4)},
            {"CurrentPOMM",           new Pair<int, int>(964,4)},
            {"NewWarning",            new Pair<int, int>(968,2)},
            {"Fault",                 new Pair<int, int>(970,2)},
            {"ForwardBack",           new Pair<int, int>(972,1)},
            {"State",                 new Pair<int, int>(974,2)},
            {"ShiftSchedule",         new Pair<int, int>(976,1)},   //班次
            {"Model",                 new Pair<int, int>(977,1)},   //产品型号
            {"Ordernum",              new Pair<int, int>(978,2)},   //订单数量
            {"CollectIdentification", new Pair<int, int>(980,8)},   //采集标识
            {"Comm1",                 new Pair<int, int>(988,16)},
            {"Comm2",                 new Pair<int, int>(1004,16)},
            {"Reads",                 new Pair<int, int>(1024,16) },//上位机读取
            {"Writes",                new Pair<int, int>(1040,16)}, //上位机写入
            {"SetReals",              new Pair<int, int>(0,255)},   //写给PLC的产品配置参数floats
            {"SetBytes",              new Pair<int, int>(256,64)},  //写给PLC的产品配置参数bytes
            {"GetReals",              new Pair<int, int>(0,255)},   //读取PLC的采集数据floats
            {"GetBytes",              new Pair<int, int>(256,64)},  //读取PLC的采集数据bytes
        };
        /// <summary>
        /// 每个产品型号下发给PLC的参数个数
        /// </summary>
        public const int ProductParaCount = 64;
        /// <summary>
        /// 允许配置的每个型号的扫码个数
        /// </summary>
        public const int ScanCount = 10;
        /// <summary>
        /// 输入输出IO点位的个数
        /// </summary>
        public const int IOCount = 16;
        /// <summary>
        /// 单页面气缸个数
        /// </summary>
        public const int CylinderCount = 5;
        /// <summary>
        /// 提示信息数量
        /// </summary>
        public const int TipsCount = 32;
        /// <summary>
        /// 警告信息数量
        /// </summary>
        public const int WarningsCount = 32;
        /// <summary>
        /// 报警信息数量
        /// </summary>
        public const int AlarmsCount = 128;
        /// <summary>
        /// plc ip
        /// </summary>
        public static readonly string PlcIp = ConfigurationManager.AppSettings["PlcIP"].ToString();
        /// <summary>
        /// plc data length
        /// </summary>
        public static readonly int DataLen = Convert.ToInt32(ConfigurationManager.AppSettings["DataLen"]);
        /// <summary>
        /// plc读取的db地址
        /// </summary>
        public static readonly int DbAddr = Convert.ToInt32(ConfigurationManager.AppSettings["DbAddr"]);
        /// <summary>
        /// 写入PLC的数据地址
        /// </summary>
        public static readonly int SetDbAddr = Convert.ToInt32(ConfigurationManager.AppSettings["SetDbAddr"]);
        /// <summary>
        /// 写入PLC的数据长度
        /// </summary>
        public static readonly int SetDataLen = Convert.ToInt32(ConfigurationManager.AppSettings["SetDataLen"]);
        /// <summary>
        /// 从PLC获取的数据地址
        /// </summary>
        public static readonly int GetDbAddr = Convert.ToInt32(ConfigurationManager.AppSettings["GetDbAddr"]);
        /// <summary>
        /// 从PLC获取的数据长度
        /// </summary>
        public static readonly int GetDataLen = Convert.ToInt32(ConfigurationManager.AppSettings["GetDataLen"]);
        /// <summary>
        /// 串口1
        /// </summary>
        public static readonly string SerialPort1 = ConfigurationManager.AppSettings["SerialPort1"].ToString();
        /// <summary>
        /// 串口2
        /// </summary>
        public static readonly string SerialPort2 = ConfigurationManager.AppSettings["SerialPort2"].ToString();
        /// <summary>
        /// 串口3
        /// </summary>
        public static readonly string SerialPort3 = ConfigurationManager.AppSettings["SerialPort3"].ToString();
        /// <summary>
        /// 串口4
        /// </summary>
        public static readonly string SerialPort4 = ConfigurationManager.AppSettings["SerialPort4"].ToString();
        /// <summary>
        /// 串口类型1
        /// </summary>
        public static readonly string SerialType1 = ConfigurationManager.AppSettings["SerialType1"].ToString();
        /// <summary>
        /// 串口类型2
        /// </summary>
        public static readonly string SerialType2 = ConfigurationManager.AppSettings["SerialType2"].ToString();
        /// <summary>
        /// 串口类型3
        /// </summary>
        public static readonly string SerialType3 = ConfigurationManager.AppSettings["SerialType3"].ToString();
        /// <summary>
        /// 串口类型4
        /// </summary>
        public static readonly string SerialType4 = ConfigurationManager.AppSettings["SerialType4"].ToString();
        /// <summary>
        /// 波特率1
        /// </summary>
        public static readonly int BaudRate1 = Convert.ToInt32(ConfigurationManager.AppSettings["BaudRate1"].ToString());
        /// <summary>
        /// 波特率2
        /// </summary>
        public static readonly int BaudRate2 = Convert.ToInt32(ConfigurationManager.AppSettings["BaudRate2"].ToString());
        /// <summary>
        /// 波特率3
        /// </summary>
        public static readonly int BaudRate3 = Convert.ToInt32(ConfigurationManager.AppSettings["BaudRate3"].ToString());
        /// <summary>
        /// 波特率4
        /// </summary>
        public static readonly int BaudRate4 = Convert.ToInt32(ConfigurationManager.AppSettings["BaudRate4"].ToString());
        /// <summary>
        /// 工位号
        /// </summary>
        public static readonly string Station = ConfigurationManager.AppSettings["Station"].ToString();

        /// <summary>
        /// 首页图片
        /// </summary>
        public static readonly string Photo = ConfigurationManager.AppSettings["Photo"].ToString();

        /// <summary>
        ///打印机名称
        /// </summary>
        public static readonly string PrintName = ConfigurationManager.AppSettings["PrintName"].ToString();
    }
}
